function showNoteMenu(){
    $("#note_list").on("click",".btn_slide_down",function(){
        //alert("0000000000000000")
        //隐藏所有菜单
        $("note_list .note_menu").hide()
        //获取点击按钮的菜单目录
        var $li = $(this).parents("li");
        var $menu = $li.find(".note_menu");
        $menu.slideDown(1000)

    })
    //追加鼠标对菜单处理
    $("#note_list").on("mouseover",".note_menu",function(){
        $(this).show()
    })
    $("#note_list").on("mouseout",".note_menu",function(){
        $(this).hide()
    })
}

function sureAddNote(){
    //获取请求参数
    var noteTile = $("#input_note").val().trim() ;
    var $li = $("#book_list li a.checked").parent();
    var bookId = $li.data("bookId");
    //发送ajax请求
    $.ajax({
        url: base_url + '/note/add.do',
        type: 'post',
        data: {"bookId":bookId,"userId":userId,"noteTile":noteTile},
        dataType:'json',
        success:function (result){
            //console.log(result)
            closeWindow();
            var noteId = result.data;
            createNoteLi(noteTile,noteId)
        },
        error:function(){
            alert('添加笔记失败！')
        }
    })
}

function createNoteLi(noteTitle,noteId){
    var s_li ='<li class="online">'
    s_li +='<a>'
    s_li +='<i class="fa fa-file-text-o" title="online" rel="tooltip-bottom">'
    s_li +='</i> ' + noteTitle
    s_li +='<button type="button" class="btn btn-default btn-xs btn_position btn_slide_down">'
    s_li +='<i class="fa fa-chevron-down">'
    s_li +='</i>'
    s_li +='</button>'
    s_li +='</a>'
    s_li +='<div class="note_menu" tabindex="-1">'
    s_li +='<dl>'
    s_li +='<dt><button type="button" class="btn btn-default btn-xs btn_move" title="移动至..."><i class="fa fa-random"></i></button></dt>'
    s_li +='<dt><button type="button" class="btn btn-default btn-xs btn_share" title="分享"><i class="fa fa-sitemap"></i></button></dt>'
    s_li +='<dt><button type="button" class="btn btn-default btn-xs btn_delete" title="删除"><i class="fa fa-times"></i></button></dt>'
    s_li +='</dl>'
    s_li +='</div>'
    s_li +='</li>'
    var $li = $(s_li);
    $li.data("noteId",noteId)
    $("#note_list").append($li)
}


function loadNoteDetail(){

    $("#note_list li a").removeClass("checked")
    //添加选中状态
    $(this).find("a").addClass("checked");
    var noteId =$(this).data("noteId")
    //console.log("noteId:" + noteId)
    $.ajax({
        url: base_url + "/note/load.do",
        type: 'post',
        data: {"id":noteId},
        success:function(result){
            if(result.status == 0){
                var noteTitle = result.data.cn_note_title;
                var noteBody = result.data.cn_note_body;
                $("#input_note_title").val(noteTitle);
                um.setContent(noteBody);
            }
        },
        error:function(){
            alert("load note detail error")
        }
    })
}


function loadNotes(){
    $("#book_list li a").removeClass("checked")
    //添加选中状态
    $(this).find("a").addClass("checked");
    //拿到当前li里的bookId
    var bookId = $(this).data("bookId")
    //console.log("bookId" + bookId)
    $.ajax({
        url: base_url + "/note/loadnotes.do",
        type: 'post',
        data: {"bookId":bookId},
        dataType: 'json',
        success:function(result){
            var notes = result.data;
            $("#note_list").empty();//清除原有笔记列表
            //console.log(result)
            for (var i=0;i<notes.length;i++){
                var noteId = notes[i].cn_note_id;
                var noteTitle = notes[i].cn_note_title;
                //拼接一个笔记li
                createNoteLi(noteTitle,noteId)
            }
        },
        error:function(){
            alert("加载笔记列表失败")
        }
    })


}